@extends('admin.public.master')
@section('content')
    <div class="content-wrapper">
        <div class="content-wrapper-before"></div>
        <div class="content-header row">
            <div class="content-header-left col-md-1 col-4 mb-2">
                <a href="{{route('classify.classify.index')}}"> <h5 class="content-header-title">分类列表</h5></a>
            </div>
            <div class="content-header-left col-md-1 col-4 mb-2">
                <a href="{{route('classify.classify.create')}}"><h5 class="content-header-title">添加分类</h5></a>
            </div>
        </div>
        <form action="{{route('classify.classify.store')}}" method="post">
            @csrf
            <div class="content-body">
                <div class="card">
                    <div class="card-body">
                        <div class="row">
                            <div class="col-6">
                                <div class="form-group">
                                    <label for="">分类名称</label>
                                    <input type="text" class="form-control" name="name"  aria-describedby="helpId" placeholder="">
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-6">
                                <div class="form-group">
                                    <label for="">父级分类</label>
                                    <select class="form-control" name="pid" id="classify">
                                        <option pid="0" value="0">顶级分类</option>
                                        @foreach($classifys as $classify)
                                                <option pid="{{$classify->pid}}" value="{{$classify->id}}">{{$classify->name}}</option>
                                                @foreach($classify->classifySon($classify->id) as $value)
                                                <option pid="{{$value->pid}}" value="{{$value->id}}"> 二级:{{$value->name}}</option>
                                                @endforeach
                                                @endforeach
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div id="attribute" style="display: none" class="row">
                            <div class="col-6">
                                @foreach($attrs as $attr)
                                <div class="form-check form-check-inline">
                                    <input name="attribute[]" class="form-check-input" type="checkbox" id="{{$attr['id']}}" value="{{$attr['id']}}">
                                    <label class="form-check-label" for="{{$attr['id']}}">{{$attr->name}}</label>
                                </div>
                                @endforeach
                            </div>
                        </div>
                    </div>
                    <div class="card-footer text-muted " >
                        <button type="submit" class="btn btn-primary ">保存数据</button>
                    </div>
                </div>
            </div>
        </form>
    </div>

@endsection
@push('js')
    <script>
        $('#classify').change(function () {
        var value= $(this).find('option:checked').attr('pid');
        if (value==0){
           $('#attribute').hide();
        } else{
            $('#attribute').show();

        }

        })
    </script>
    @endpush

